<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="/shop/shop/Public/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="/shop/shop/Public/Css/common.css" />
	<script type="text/javascript" src='/shop/shop/Public/Js/jquery-1.7.2.min.js'></script>
	<style type="text/css">
		body{
			margin-bottom: 100px;
		}
	</style>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">


	<form action="" method='post'>

		<table class='table table-bordered table-hover'>
			<tr>
				<th>货品ID</th>

				<?php if(is_array($spec)): foreach($spec as $key=>$v): ?><th><?php echo ($v["taname"]); ?></th><?php endforeach; endif; ?>

				<th>库存</th>
				<th>货号</th>
			</tr>

			<tr class="info">
				<td><?php echo ($_GET['glid']); ?></td>

				<?php if(is_array($spec)): foreach($spec as $e=>$v): ?><td>
						<select name="spec[]">
							<option value="0">-请选择-</option>
							<?php if(is_array($v["opt"])): foreach($v["opt"] as $k=>$s): ?><option <?php if($oldData['combine'][$e]==$s['gtvalue']): ?>selected<?php endif; ?> value="<?php echo ($s["gtid"]); ?>"><?php echo ($s["gtvalue"]); ?></option><?php endforeach; endif; ?>
						</select>
					</td><?php endforeach; endif; ?>


				<td>
					<input type="text" name='inventory' value="<?php echo ($oldData['inventory']); ?>">
				</td>
				<td>
					<input type="text" name='number'  value="<?php echo ($oldData['number']); ?>">
				</td>
				<td></td>
			</tr>

		</table>

		<input type="hidden" name='gid' value='<?php echo ($_GET['gid']); ?>'/>
		<input type="hidden" name='tid' value='<?php echo ($_GET['tid']); ?>'/>
		<input type="submit" value='确认修改' class="btn btn-primary"/>
	</form>

	</div>
	</div>
	</div>

</body>
</html>
<script type="text/javascript">
	var sel = $('select[name="spec[]"]');
	var len = sel.length;
	sel.change(function () {
		var remote = {
					'gid' : <?php echo ($_GET['gid']); ?>,
				'spec' : {}
	};
		for (var i = 0; i < len; ++i)
		{
			if (sel.eq(i).val() == 0){
				return;
			}else{
				remote.spec[i] = sel.eq(i).val();
			}
		}
		$.ajax({
			url : '<?php echo U("check");?>',
			type : 'get',
			data : remote,
			dataType : 'json',
			success : function(data)
			{
				if (data == 0)
				{
					alert('货品已存在');
					for (var i = 0; i < len; ++i)
					{
						sel.eq(i).val(0);
					}
				}
			}
		});
	});
</script>